package com.jinzhi.api.controller;

import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.utils.Result;
import com.jinzhi.oss.service.FileService;
import com.jinzhi.oss.service.OssService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <pre>
 *  基于jwt实现的API测试类
 * </pre>
 *
 * <small> 2018年4月27日 | Aron</small>
 *
 */
@RestController
@RequestMapping("/api/oss/")
@AllArgsConstructor
public class AppOssController {
    @Autowired
    private OssService ossService;

    private FileService fileService;

    @Log("上传文件")
    @ResponseBody
    @PostMapping("/upload")
    @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Authorization", paramType = "header") })
    Result<String> upload(@RequestParam("file") MultipartFile file) {
        String url = "";
            //url = fileService.upload(file.getBytes(), file.getOriginalFilename());
            url = ossService.uploadFileOss(file);
        return Result.ok(url);
    }

}
